function Obstacle (ctx) {
  this.x = 1200;
  this.y = 0; 
  this.w = 83;
  this.h = 78;
  this.type = 1;
  this.ctx = ctx;
  this.n = 0; // 记录帧数 
  this.index = 0; // 图片索引 用于动画图片
  this.speed = 10;  
  this.list = [];
}



Obstacle.prototype = {
  draw() {  
    this.list.forEach(v=> {
      v.draw();
    })
    if (this.list[0].x <-100) {
      // 删除移除的元素 
      this.list.shift();
    }
    if ( this.list.length < 5 && sence.width - this.list[this.list.length -1].x >  this.list[this.list.length -1].distance ) {
      this.addObstacle();
    }
  },

  addObstacle(obj) {
    let r = Math.random();
    console.log(r);
    if (r > 0.8) {
      let b = new Bird(this.ctx);
      this.list.push(b);
    } else {
      let t = new Tree({}, this.ctx);
      this.list.push(t);
    }
  },

  removeObstacle() {
    this.list.unshift();
  }
}